Go to Home Page
Questions?
Call 1-800-572-5517
 
  Go to Home Page  
  See all products
  See price schedules
  See manuals, tutorials, articles
  Download a free 30-day trial
  See user testimonials
  About Pacific Systems Group
 
 
SMF Tools
  See SMF Record Layouts
  See Sample SMF Reports
  Learn How to Export SMF Data
  Download Free SMF Reporting Software (30 days)
 
One of the greatest SMF record parsing programming languages I've ever seen. Chief, Large Systems Services Branch, NIH
  Choose Spectrum Writer to add 4GL to your product
  Report Writer Speedup Tips Article
Spectrum SMF Writer - the 4GL SMF Report Writer.

Add customized reports and PC export files to your product!

Table of Contents

NOTE: you can find this and other lessons in a
more complete and viewable format (including all Figures) in our Tutorial PDF.

Lesson 8. Conditional COMPUTE Statements

COMPUTE statements with conditional parms. We will even show how conditional COMPUTE statements help you report on data from different types of SMF records in a single report.
  • The control statement discussed is:
  • the WHEN , ASSIGN and ELSE parms of the COMPUTE statement
  • The previous lesson explained how to write simple COMPUTE statements. But it is also possible to use conditional logic in a COMPUTE statement. In conditional COMPUTE statements, one of multiple different expressions will be used to assign a value to the new field. The expression that is used will depend on one or more conditions that you specify. Conditional COMPUTE statements can be very powerful tools in producing reports.
  • remember this construction well. It will come in handy for many different applications. Sometimes we are asked why Spectrum SMF Writer has no "IF" statement and how to get around that. And often, the answer to the question is to use this if-type logic within a COMPUTE statement.
  • Conditional COMPUTE Syntax
    1. The conditional COMPUTE statement has this syntax:

    COMPUTE: fieldname = WHEN(conditional-expression) ASSIGN(computational-expression)
    = WHEN(conditional-expression) ASSIGN(computational-expression)
    = WHEN(conditional-expression) ASSIGN(computational-expression)
    . . .
    ELSE ASSIGN(computational-expression)

    1. When Spectrum SMF Writer needs to compute the value of such a field, it begins by evaluating the conditional expressions within the WHEN parms. The WHEN parms are processed in order, one by one. As soon as a WHEN parm is found that is true, Spectrum SMF Writer assigns the value from the corresponding ASSIGN expression to the compute field. At that point, no further WHEN parms are examined.
    2. If none of the WHEN expressions are true, then the value from the ELSE ASSIGN parm, if present, is assigned to the result. If no ELSE ASSIGN parm was specified, then a value of blanks or zeros will be assigned to the compute field (depending on the data type.)
    3. Now let's look at some examples of how conditional COMPUTE statements can help with report logic.
    Using COMPUTEs to Reformat the Completion Code
    Assigning values to computed fields based on conditions
    Assigning values to computed fields based on conditions
     
    1. In an earlier report in Figure _, we showed the system completion code ( SMF30SCC ) from the SMF 30 subtype 5 records. In that report, we simply displayed the completion code in hex.
    2. But we might want to format that code in a more useful way. There are several different types of non-zero completion codes: system abends, user abends and regular non-abend completion codes. Each of these cases is usually formatted a little differently (in, for example, a job's SYSLOG):
    3. S0C4 for System ABEND codes. ("S" + hex value)
    4. U1000 for User ABEND codes. ("U" + decimal value)
    5. 0012 for non-abend completion codes (decimal value)
    6. We can use a conditional COMPUTE statement along with some built-in functions to format a new COMP-CODE field in one of these standard ways. To choose the format, we will examine the abend bit in SMF30STI (step termination indicator) as well as the first nibble of the SMF30SCC field. (A first nibble value of X'8' signals a user abend, as opposed to a system abend.)

    COMPUTE: ABEND-BIT = #SUBSTR(#FORMAT(SMF30STI,BITS),7,1)

     

    COMPUTE: CC-HEX = #FORMAT(SMF30SCC,HEX)

    COMPUTE: CC-NIB1 = #SUBSTR(CC-HEX,1,1)

    COMPUTE: CC-DROP-8 = SMF30SCC + 32768 /* BIN VALUE W/O LEADING X'8' */

     

    COMPUTE: COMP-CODE =

    WHEN(SMF30SCC = 0) ASSIGN(' ')

    WHEN(ABEND-BIT = '0') ASSIGN(#FORMAT(SMF30SCC,P'ZZZZ9'))

    WHEN(CC-NIB1 = '0') ASSIGN('S' + #SUBSTR(CC-HEX,2,3))

    WHEN(CC-NIB1 = '8') ASSIGN('U' + #FORMAT(CC-MINUS-8,P'ZZZ9'))

     

    1. The above code first extracts just the abend bit out of the 2-byte SMF30STI field. Two other COMPUTE statements extract just the first nibble from the SMF30SCC field. Another calculates the binary value of the SMF30SCC field, after ignoring the X'8' user abend indicator (which is in the sign bit.)
    2. The conditional COMPUTE statement for COMP-CODE formats our final result. When SMF30SCC is 0, we just set COMP-CODE to blanks. Otherwise, if the abend bit is off we set COMP-CODE to a normal completion code value. Otherwise, if the first nibble of SMF30SCC is 0, we format the remaining three hex digits with an S prefix, as a system abend code. Otherwise, if the first nibble is '8' we format the rest of the SMF30SCC field as a binary user abend value with a U prefix.
    3. The report in Figure _ uses these COMPUTE statements.
    Using COMPUTEs to Report on Different SMF Record Types
    A report showing data from SMF 15 and SMF 17 records
    A report showing data from SMF 15 and SMF 17 records
     
    1. Here is a technique for reporting on two different SMF record types in the same report.
    2. Let's say that we want a report that shows all changes made to any dataset with " SPFTEMP " in its name. We want to include all jobs that wrote to the dataset, as well as any jobs that may have deleted it. To do that, we need to combine the information from SMF 15 records (logged when a DD is opened for output) and SMF 17 records (logged when a dataset is deleted.)
    3. Since we will be working with fields from two different SMF types, we will need the field definitions for both of them. The following statements handle that for us:

    INPUT: SMF15 /* GET TYPE 15 FILE AND FIELD DEFINITIONS */
    COPY: REC17 /* GET TYPE 17 FIELD DEFINITIONS ONLY */

    1. The INPUT statement above does two things. It reads in the file and field definitions for the type 15 records from the copy library. And it names that file as the input for the report. Since we cannot have multiple INPUT statements in a run, we use a COPY statement to copy in the additional field definitions for the type 17 records. We copied member REC 17 rather than SMF17 because we want to add all of the type 17 SMF fields to the existing SMF 15 file definition. (Copying SMF17 would have defined a new, second file containing the SMF 17 fields. That is not what we want.)
    2. Our INCLUDEIF statement should now include both type 15 and type 17 records in the report. Since the SMF record type field is located in the same position for all SMF records (in the fixed SMF header), it is safe for us to test the SMF15RTY field in all records.

    INCLUDEIF: (SMF15RTY = 15 OR 17) /* SELECT BOTH 15 AND 17*/

    1. We also want to restrict the records in our report to just those which contain the text " SPFTEMP " somewhere within the dataset name. However, the dataset name in SMF15 records is not in the same place as it is in SMF17 records. So we can not make this test directly on any one field in the input record. This is where a conditional COMPUTE statement is useful.

    COMPUTE: DSN = WHEN(SMF15RTY=15) ASSIGN(SMF15_JFCBDSNM)
    ELSE ASSIGN(SMF17DSN)

    1. The COMPUTE statement assigns SMF15_JFCBDSNM to DSN when the input record is type 15. Otherwise, it assigns SMF17DSN , from a different part of the record, to DSN.
    2. Now we have a single field where we can look for the text " SPFTEMP ". So our final INCLUDEIF statement will be this:

    INCLUDEIF: (SMF15RTY = 15 OR 17) /* SELECT BOTH 15 AND 17*/
    AND DSN : 'SPFTEMP' /* ":" MEANS SCAN FOR TEXT */

    1. Now that the input and inclusion criteria have been specified, we just need to specify what columns to put in the report. Once again, for some items we must make COMPUTE fields to use in the COLUMNS statement (rather than a field name which may or may not be valid for a given record.) Other fields (such as SMF15DTE and SMF15TME ) are located in the standard SMF header and can be used with any type of SMF record.
    2. The report in Figure _ now has one line for each type 15 or 17 record that refers to a " SPFTEMP " dataset. Each report line shows relevant data taken from either SMF 15 fields or from SMF 17 fields.
    Summary
    1. Here is a summary of what we learned in this lesson:
    2. a conditional COMPUTE statement uses one of multiple different computational expressions, depending on the conditions that you specify
    3. you may have any number of WHEN/ASSIGN pairs
    4. optionally, you may have a final ELSE/ASSIGN pair as well
    5. you can use a conditional COMPUTE statement to construct report lines using data from 2 different types of SMF records
    To Learn More
    1. You can also learn:
    2. how to create date fields ()
    3. many powerful date manipulation functions, listed in
    4. how to create bit (boolean) fields ()
    5. how to specify the number of decimal places a numeric or time field should contain ()
    6. how to retain the previous value of a COMPUTE field in certain cases ()
    7. the complete syntax for the COMPUTE statement, in .
    NEXT LESSON: How to Specify the Sort Order and Control Breaks

    Spectrum SMF Writer - the 4GL SMF Report Writer.

    Copyright 2024.
    Pacific Systems Group.
    All rights reserved.
    Home | Products | Prices | Documentation | 30-Day Trials | Customer Reviews | Company | FAQ | Sample Reports | SMF Records
    Send Your Comments or Questions